#include "King.h"

King::King(enum FigureColor color) : Figure(color)
{
}

QString King::getImage() const
{
    if(color == BLACK)
        return "./images/blackking.png";
    else
        return "./images/whiteking.png";
}

AllMoves King::moves() const
{
    AllMoves m;
    int x, y, position[2];

    Position::position2index(currentPosition, position);

    x = position[1];
    y = position[0];

    if(y - 1 >= 0) {
        if(x - 1 >= 0) {
            QVector <int> coords(2);
            coords[0] = y - 1;
            coords[1] = x - 1;
            m.append(coords);
        }

        QVector <int> coords(2);
        coords[0] = y - 1;
        coords[1] = x;
        m.append(coords);

        if(x + 1 <= 7) {
            QVector <int> coords(2);
            coords[0] = y - 1;
            coords[1] = x + 1;
            m.append(coords);
        }
    }

    if(y + 1 <= 7) {
        if(x - 1 >= 0) {
            QVector <int> coords(2);
            coords[0] = y + 1;
            coords[1] = x - 1;
            m.append(coords);
        }

        QVector <int> coords(2);
        coords[0] = y + 1;
        coords[1] = x;
        m.append(coords);

        if(x + 1 <= 7) {
            QVector <int> coords(2);
            coords[0] = y + 1;
            coords[1] = x + 1;
            m.append(coords);
        }
    }

    if(x - 1 >= 0) {
        QVector <int> coords(2);
        coords[0] = y;
        coords[1] = x - 1;
        m.append(coords);
    }

    if(x + 1 <= 7) {
        QVector <int> coords(2);
        coords[0] = y;
        coords[1] = x + 1;
        m.append(coords);
    }


    return m;
}
